import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { GoodsCategoryVO, GoodsCategoryForm, GoodsCategoryQuery, categoryParentVO } from '@/api/mall/goodsCategory/types';

/**
 * 查询商品分类列表
 * @param query
 * @returns {*}
 */

export const listGoodsCategory = (query?: GoodsCategoryQuery): AxiosPromise<GoodsCategoryVO[]> => {
  return request({
    url: '/mall/goodsCategory/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询商品分类详细
 * @param id
 */
export const getGoodsCategory = (id: string | number): AxiosPromise<GoodsCategoryVO> => {
  return request({
    url: '/mall/goodsCategory/' + id,
    method: 'get'
  });
};
/**
 * TODO 查询父级分类,这个功能暂时不用
 * @param id
 */
export const getParentApi = (id: string | number): AxiosPromise<categoryParentVO> => {
  return request({
    url: '/mall/goodsCategory/parent/' + id,
    method: 'get'
  });
};

/**
 * 新增商品分类
 * @param data
 */
export const addGoodsCategory = (data: GoodsCategoryForm) => {
  return request({
    url: '/mall/goodsCategory',
    method: 'post',
    data: data
  });
};

/**
 * 修改商品分类
 * @param data
 */
export const updateGoodsCategory = (data: GoodsCategoryForm) => {
  return request({
    url: '/mall/goodsCategory',
    method: 'put',
    data: data
  });
};

/**
 * 删除商品分类
 * @param id
 */
export const delGoodsCategory = (id: string | number | Array<string | number>) => {
  return request({
    url: '/mall/goodsCategory/' + id,
    method: 'delete'
  });
};
